package com.starsoft.quant.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.starsoft.frame.core.orm.BaseDao;
import com.starsoft.quant.bean.QuantSummary;
import com.starsoft.quant.bean.QuantSummaryId;

@Repository
public class QuantSummaryDao extends BaseDao<QuantSummary, QuantSummaryId> {

	public QuantSummary get(Integer acountId, Date date){
		QuantSummaryId summayId = new QuantSummaryId(acountId, date);
		return get(summayId);
	}
	
	public int deleteReportBetween(Integer acountId, Date beginDate, Date endDate) {
		int count;
		String hql = "delete from QuantSummary where id.acountId = ?0";
		if (beginDate == null && endDate == null) {
			count = update(hql, acountId);
		} else if (beginDate != null && endDate != null) {
			hql += " and id.summaryDate>=?1 and id.summaryDate<=?2";
			count = update(hql, acountId, beginDate, endDate);
		} else if (beginDate != null) {
			hql += " and id.summaryDate>=?1";
			count = update(hql, acountId, beginDate);
		} else {
			hql += " and id.summaryDate<=?1";
			count = update(hql, acountId, endDate);
		}
		return count;
	}
	
}
